package org.bzjj.servlet.update;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bzjj.bean.insert.VEH_IS_INOUT_REQ;
import org.bzjj.tool.ChatMethod;
import org.bzjj.tool.Tools;

import org.bzjj.sql.OracleCon;
import org.bzjj.sql.Sql;
import org.bzjj.sql.SqlInsert;
import org.bzjj.sql.SqlSelect;



public class CarReqUpdate extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String qqxlh = request.getParameter("qqxlh");
		//查询mysql该信息是否处理过
		HashMap<String, String> where = new HashMap<String, String>();
		where.put("qqxlh", qqxlh);
		String rtn=Sql.executeQuery(SqlSelect.getSelect("process", "qqxlh",where));
		
		if(rtn!=null){
			ChatMethod.setResponse(response, "该信息已经处理过，可能边界传输存在问题，请勿再试！");
			return;
		}
		// 备份语句
		String path = "d:\\log\\" + "req_" + qqxlh + ".sql";
		String instr = VEH_IS_INOUT_REQ.getInsert(qqxlh);
		Tools.saveSql(path, instr);

		// 处理信息写入mysql
		HashMap<String, String> value = new HashMap<String, String>();
		value.put("qqxlh", qqxlh);
		Sql.executeUpdate(SqlInsert.getInsert("process", value));

		Connection connection = OracleCon.getDBonnect().getConnection();
		// oracle中更新该条信息qqzt
		Sql.executeUpdate(connection, "update veh_is_inout_req set qqzt='1' where qqxlh="+qqxlh);
		
		try {
			connection.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// 返回处理结果,成功返回1，失败返回提示信息
		ChatMethod.setResponse(response, "1");

	}
}
